package com.mayn.web.fee;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.jfinal.core.Controller;
import com.mayn.jst.login.TaobaoLoginAction;
import com.mayn.jst.shop.action.ShopAccountAction;
import com.mayn.jst.task.AllShopLoginTask;
import com.mayn.jst.task.GetAllShopDataTask;
import com.mayn.util.DateUtil;
import com.mayn.web.dsr.DsrController;

public class FeeController extends Controller {

	private static final Logger LOG = LoggerFactory.getLogger(DsrController.class);

	public void index() {
		renderText("Hello Fee");
	}

	public void Forcelogin() {
		LOG.info("强制重新登陆开始--");
		AllShopLoginTask.ForceLoginAll();
		LOG.info("强制重新登陆结束--");
		renderText("强制重新登陆");
	}
	
	public void CheckLogin() {
		AllShopLoginTask.CheckAndLoginAll();
		renderText("检查cookie");

	}

	public void CheckAll() {
		LOG.info("重新采集--");
		GetAllShopDataTask.getAll();
		LOG.info("重新采集结束--");
		renderText("重新采集");
	}
	
	public void TestToken() throws UnsupportedEncodingException{
		TaobaoLoginAction.checkAndSaveTaobaoLoginCookie(5);
		String cookie = ShopAccountAction.getShopAccountCookie(5);

		HashMap<String, String> info = TaobaoLoginAction.getZuanshiWebPageInfo(cookie);
		LOG.info("csrfID:" + info.get("csrfID"));
		LOG.info("rptToken:" + info.get("rptToken"));
		LOG.info("unix time:" + DateUtil.getUnixTime());
		
		LOG.info(URLEncoder.encode(info.get("rptToken"),"UTF-8"));
		LOG.info("钻石展位费用:" + TaobaoLoginAction.getZuanshiFeeValue("2017-03-23",cookie));
		LOG.info("钻石展位费用:" + TaobaoLoginAction.getZuanshiFeeValue("2017-03-22",cookie));
		
		renderText("test");
	}
}
